import '../utils/date_utils.dart';
import 'paging_model.dart';
import 'result_model.dart';

///考试等级:查询:请求
class TestLevelQueryReq extends PagingQueryReq {
  final String tenantId, semesterId, name;
  final int status;

  TestLevelQueryReq({
    required this.tenantId,
    required this.semesterId,
    required this.name,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['semesterId'] = semesterId;
    map['name'] = name;
    map['status'] = status;
    return map;
  }
}

///考试等级:查询:响应
class TestLevelQueryRes extends PagingQueryRes<TestLevelItemRes> {
  TestLevelQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory TestLevelQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => TestLevelItemRes.fromMap(row),
    );
    return TestLevelQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

///考试等级:数据项:响应
class TestLevelItemRes {
  final String id, name, remark, semesterId;
  final int status;
  final DateTime? createdAt;

  const TestLevelItemRes({
    required this.id,
    required this.name,
    required this.remark,
    required this.semesterId,
    required this.status,
    required this.createdAt,
  });

  factory TestLevelItemRes.fromMap(final Map<String, dynamic> map) =>
      TestLevelItemRes(
        id: map['id'] ?? '',
        name: map['name'] ?? '',
        remark: map['remark'] ?? '',
        semesterId: map['semesterId'] ?? '',
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

///考试等级:加载:响应
class TestLevelInfoRes extends TestLevelItemRes with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  TestLevelInfoRes({
    required this.retCode,
    required this.retMessage,
    required TestLevelItemRes item,
  }) : super(
          id: item.id,
          name: item.name,
          remark: item.remark,
          semesterId: item.semesterId,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory TestLevelInfoRes.fromModel(final ResultModelRes res) =>
      TestLevelInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: TestLevelItemRes.fromMap(res.toMap),
      );
}

///考试等级:新增:请求
class TestLevelAddReq {
  final String tenantId, name, remark, semesterId;

  TestLevelAddReq({
    required this.tenantId,
    required this.name,
    required this.remark,
    required this.semesterId,
  });

  Map<String, dynamic> toMap() => {
        'name': name,
        'remark': remark,
        'semesterId': semesterId,
      };
}

///考试等级:修改:请求
class TestLevelModifyReq {
  final String id, name, remark, semesterId;
  final int status;

  const TestLevelModifyReq({
    required this.id,
    required this.name,
    required this.remark,
    required this.semesterId,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'name': name,
        'remark': remark,
        'semesterId': semesterId,
        'status': status,
      };
}
